package user_assets_ewallet

import (
	"context"
	"strconv"

	"gitee.com/liuxuezhan/ar-platform/rpc-client/assetsClient/rpc"

	"gitee.com/liuxuezhan/ar-platform/admin-api/internal/svc"
	"gitee.com/liuxuezhan/ar-platform/admin-api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type UserEWalletInsertInfoLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

// 添加
func NewUserEWalletInsertInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UserEWalletInsertInfoLogic {
	return &UserEWalletInsertInfoLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *UserEWalletInsertInfoLogic) UserEWalletInsertInfo(req *types.UserEWalletsInsertRequest) (resp *types.UserEWalletsInsertResponse, err error) {
	_, err = l.svcCtx.AssetsRpc.UserChannel.UserEWalletsInsert(l.ctx, &rpc.UserEWalletsInsertRequest{
		UserId:   req.UserID,
		Name:     strconv.FormatInt(int64(req.WalletName), 10),
		Username: req.Username,
		Account:  req.Account,
	})

	if err != nil {
		return &types.UserEWalletsInsertResponse{
			IsInsert: false,
		}, err
	}
	return &types.UserEWalletsInsertResponse{
		IsInsert: true,
	}, err
}
